package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;

import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingWorker;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import mail.Mail;
import mail.MyModelEmail;
import todo.MyTask;
import tools.OptionReader;
import calendar.CheckboxCalendar;

/**
 * Erstellt ToDo Panel, welches innerhalb des ToDo Bereichs eingefuegt wird
 * 
 * @author frederikroessler
 * 
 */
public class ToDoPane extends JPanel {

	private static final long serialVersionUID = 3684069578706506791L;
	private Connection connection = null;

	// Sprachen (0 = deutsch; 1 = englisch; 2 = latein)
	int speak = 0;
	int sorted = 0;
	int zuerstDatum = 0;

	String[] titel = { "Titel", "heading", "titulus" };
	String[] abgabe = { "Abgabedatum", "deadline", "spatium" };
	String[] prior = { "Priorität", "priority", "interest" };
	String[] teilnehmer = { "Teilnehmer", "participants", "auditor" };
	String[] kalendar = { "Kalender", "calendar", " calendarium" };
	String[] beschreibung = { "Beschreibung", "description", "explicatio" };

	String[] editbutton = { "Bearbeiten", "Edit", "Incudo" };
	String[] savebutton = { "Speichern", "Save", "Demuto" };

	String[] tooltipAdd = { "Fuegen sie einen neuen Aufgabe hinzu.",
			"Add a new task.", "Addicere addunt novum negotium." };
	String[] tooltipDelete = { "Loescht die ihnen angezeigte Aufgabe.",
			"Delete the selected task.", "Errarum delectorum labor." };
	String[] tooltipNext = { "Zeigt die nächste Aufgabe an", "Show next task.",
			"Ostende proximus huic labor" };
	String[] tooltipLast = { "Zeigt die vorherige Aufgabe an",
			"Show previous task.", "Ostende previous labor." };
	String[] tooltipAktuell = {
			"Hier wird Ihnen der Name der aktuell ausgewählten Aufgabe angezeit",
			"Show the name of the selected task.",
			"Ostende nomen delectorum labor." };
	String[] tooltipSort = { "Hier können sie die Sortierung ändern",
			"Change they way tasks are sorted",
			"Hic vos potest mutare diribitio" };

	String[] prioHoch = { "hoch", "high", "altus" };
	String[] prioMittel = { "mittel", "medium", "medium" };
	String[] prioTief = { "niedrig", "low", "penitus" };

	//

	// Textfelder fuer Detailangaben zu jeweiligen Tasks
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JComboBox kalender;
	private LinkedList<CheckboxCalendar> cals = new LinkedList<CheckboxCalendar>();
	private String[] calDropdown;
	private OptionReader or;
	private String[] windowColorsSeperated;
	private int r;
	private int g;
	private int b;
	private JCheckBox cB;
	private JButton taskBearbeitenButton;
	private JButton saveButton;
	private JButton sortButton;
	private LinkedList<String> emailLinkedList;

	private Icon tickSort;
	private Icon datumSort;

	JPanel centerpanel;

	JComboBox tag = new JComboBox();

	JComboBox monat = new JComboBox();

	JComboBox jahr = new JComboBox();
	JComboBox priority = new JComboBox();

	Date d = new Date();
	@SuppressWarnings("deprecation")
	int y = d.getYear();

	private int globalselectedid;

	public int getGlobalselectedid() {
		return globalselectedid;
	}

	public void setGlobalselectedid(int globalselectedid) {
		this.globalselectedid = globalselectedid;
	}

	private JTextArea textArea;
	private JTextField aktuellerTask;
	private LinkedList<MyTask> taskslinkedlist = new LinkedList<MyTask>();
	@SuppressWarnings("rawtypes")
	private LinkedList participants = new LinkedList();

	@SuppressWarnings("rawtypes")
	public LinkedList getParticipants() {
		return participants;
	}

	@SuppressWarnings("rawtypes")
	public void setParticipants(LinkedList ll) {
		this.participants = ll;
	}

	public LinkedList<MyTask> getTaskslinkedlist() {
		return taskslinkedlist;
	}

	public void setTaskslinkedlist(LinkedList<MyTask> taskslinkedlist) {
		this.taskslinkedlist = taskslinkedlist;
	}

	final DefaultListModel dlm;

	final JList tasklist;

	ResultSet temp;

	private ToDoPane tdp;
	JLabel arrowLeftPicLabel;
	JLabel arrowRightPicLabel;
	JButton previousTaskButton;
	JButton nextTaskButton;

	private boolean activated = true;

	private boolean listselectionactivated = true;

	/**
	 * Stellt Verbindung zur DB her
	 * 
	 * @return
	 */
	public boolean connect() {

		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager
					.getConnection("jdbc:mysql://win9142.informatik.uni-wuerzburg.de:3306?user=awesomefireballs&password=jesus");

		} catch (ClassNotFoundException e) {

			e.printStackTrace();
		} catch (SQLException e) {

			e.printStackTrace();
			return false;
		}

		return true;
	}

	/**
	 * Gibt ein RS mit allen Tasks, welcher der User besitzt zuerueck
	 * 
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getTasksFromDb() throws SQLException {

		Statement stat = connection.createStatement();

		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		@SuppressWarnings("unused")
		String hans = "'hans'";

		ResultSet rs = stat
				.executeQuery("SELECT Task.*  FROM Task, Calendar, Books, User where Task.idToDo = Calendar.idCalendar AND Calendar.idUser = User.idUser AND User.idUser= "
						+ Test.iduser
						+ " group by Task.idTask ORDER BY Task.enddate;");

		return rs;

	}

	/**
	 * Gibt ein RS mit allen Teilnehmern von einem Task zurueck
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getParticipants(int id) throws SQLException {

		Statement stat = connection.createStatement();

		Integer help = new Integer(id);
		String idString = "'" + help.toString() + "'";

		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		ResultSet rs = stat
				.executeQuery("SELECT Adress.* FROM Task, participantsToDo, Adress where Task.idTask = "
						+ idString
						+ "AND Adress.idAdress = participantsToDo.idAdress AND participantsToDo.idTask = Task.idTask group by Adress.idAdress;");

		return rs;

	}

	/**
	 * Gibt Liste zurueck mit zu Events zugehöerigen Kalendern
	 * 
	 * @return
	 * @throws SQLException
	 * @throws ClassNotFoundException
	 */
	public LinkedList<Integer> getCalIds() throws SQLException,
			ClassNotFoundException {

		Class.forName("org.sqlite.JDBC");
		Connection conn = DriverManager
				.getConnection("jdbc:sqlite:checkids.db");
		Statement stat2 = conn.createStatement();

		ResultSet rs2 = stat2.executeQuery("select * from ids;");

		LinkedList<Integer> ids = new LinkedList<Integer>();

		while (rs2.next()) {
			ids.add(rs2.getInt("id"));

		}

		return ids;
	}

	/**
	 * Im Konstruktor wird JPanel erstellt
	 * 
	 * @throws ClassNotFoundException
	 */
	public ToDoPane() {

		or = new OptionReader();

		try {
			or.getOpionsFromFile();
		} catch (IOException e2) {

			e2.printStackTrace();
		}

		String windowColors = or.getColorSetting();
		windowColorsSeperated = windowColors.split(",");
		r = Integer.parseInt(windowColorsSeperated[0]);
		g = Integer.parseInt(windowColorsSeperated[1]);
		b = Integer.parseInt(windowColorsSeperated[2]);

		speak = Integer.parseInt(or.getLanguage());
		sorted = Integer.parseInt(or.getToDoOpt1());
		zuerstDatum = Integer.parseInt(or.getToDoOpt2());

		Dimension size = new Dimension(900, 500);
		setSize(size);
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);

		setBackground(Color.LIGHT_GRAY);
		setLayout(new BorderLayout(0, 0));

		/**
		 * Leiste, welche alle Button f�r Antowrten, Weiterleiten etc. enth�lt
		 */

		JPanel buttonPanel = new JPanel();
		buttonPanel.setBackground(new Color(r, g, b));
		buttonPanel.setSize(new Dimension(260, 40));
		buttonPanel.setPreferredSize(new Dimension(260, 40));
		buttonPanel.setMinimumSize(new Dimension(260, 40));
		buttonPanel.setMaximumSize(new Dimension(260, 40));
		add(buttonPanel, BorderLayout.NORTH);
		GridBagLayout gbl_buttonPanel = new GridBagLayout();
		gbl_buttonPanel.columnWidths = new int[] { 80, 40, 40, 40, 80, 40, 40,
				40, 0, 0 };
		gbl_buttonPanel.rowHeights = new int[] { 0, 0 };
		gbl_buttonPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
		gbl_buttonPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
		buttonPanel.setLayout(gbl_buttonPanel);

		/**
		 * Button oeffnet ToDohinzufuegen Dialog
		 */

		Icon iconHinzu = new ImageIcon("src/pictures/add.png");
		JButton hinzufuegenButton = new JButton(iconHinzu);
		hinzufuegenButton.setToolTipText(tooltipAdd[speak]);

		hinzufuegenButton.setMaximumSize(new Dimension(40, 40));
		hinzufuegenButton.setMinimumSize(new Dimension(40, 40));
		hinzufuegenButton.setPreferredSize(new Dimension(40, 40));
		GridBagConstraints gbc_button = new GridBagConstraints();
		gbc_button.fill = GridBagConstraints.HORIZONTAL;
		gbc_button.insets = new Insets(0, 0, 0, 5);
		gbc_button.gridx = 0;

		gbc_button.gridy = 0;

		tdp = this;

		ActionListener addTask = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				setListselectionactivated(false);
				JFrame ntw = new NewTaskWindow(tdp);
				ntw.setVisible(true);

			}

		};

		hinzufuegenButton.addActionListener(addTask);

		buttonPanel.add(hinzufuegenButton, gbc_button);

		/**
		 * Button loescht ausgewaehlten Task
		 * 
		 */

		Icon iconLoeschen = new ImageIcon("src/pictures/bin.png");
		JButton taskEntfernenButton = new JButton(iconLoeschen);
		taskEntfernenButton.setToolTipText(tooltipDelete[speak]);
		taskEntfernenButton.setPreferredSize(new Dimension(40, 40));
		taskEntfernenButton.setMinimumSize(new Dimension(40, 40));
		taskEntfernenButton.setMaximumSize(new Dimension(40, 40));
		GridBagConstraints gbc_button_1 = new GridBagConstraints();
		gbc_button_1.insets = new Insets(0, 0, 0, 5);
		gbc_button_1.gridx = 1;
		gbc_button_1.gridy = 0;

		ActionListener remove = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (globalselectedid != 0) {
					listselectionactivated = false;
					@SuppressWarnings("rawtypes")
					SwingWorker worker = new SwingWorker() {
						@Override
						public Object doInBackground() {

							Statement stat = null;
							try {
								int i = globalselectedid;
								stat = connection.createStatement();
								stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");
								stat.executeUpdate("DELETE FROM `sopra-ws12-awesome_fireballs`.`Task` WHERE `idTask`="
										+ i + ";");

							} catch (SQLException e) {
								e.printStackTrace();
							}
							return stat;

						}

						@Override
						public void done() {

							if (sorted == 1) {
								updateSorted();
							}
							if (sorted == 0) {
								update();
							}

							listselectionactivated = true;

						}

					};
					worker.execute();

				}

			}

		};
		taskEntfernenButton.addActionListener(remove);

		buttonPanel.add(taskEntfernenButton, gbc_button_1);

		/**
		 * Task Bearbeiten Button
		 */

		Icon iconEdit = new ImageIcon("src/pictures/edit.png");

		taskBearbeitenButton = new JButton(iconEdit);
		taskBearbeitenButton.setToolTipText(editbutton[speak]);
		taskBearbeitenButton.setMinimumSize(new Dimension(40, 40));
		taskBearbeitenButton.setMaximumSize(new Dimension(40, 40));
		taskBearbeitenButton.setPreferredSize(new Dimension(40, 40));
		GridBagConstraints gbc_btnWtl = new GridBagConstraints();
		gbc_btnWtl.insets = new Insets(0, 0, 0, 5);
		gbc_btnWtl.gridx = 2;
		gbc_btnWtl.gridy = 0;

		// Setzt Textfelder rechts auf Bearbeitbar und speichert vorgenommene
		// Änderungen
		ActionListener editTask = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				listselectionactivated = false;
				// String text = e.getActionCommand();

				tasklist.setEnabled(false);
				taskBearbeitenButton.setEnabled(false);
				saveButton.setEnabled(true);
				previousTaskButton.setEnabled(false);
				nextTaskButton.setEnabled(false);

				activated = false;

				// die alten textfelder werden in Strings gespeichert
				textField_1.setVisible(false);
				kalender.setEnabled(true);
				// DATE !!!
				// Datum
				int intjahr = 0;
				int intmonat = 0;
				int inttag = 0;
				String date = textField_1.getText();

				if (date.equals("")) {
					intjahr = -1;
					intmonat = -1;
					inttag = -1;
				} else {

					String[] values = date.split("\\.");

					String pJ = values[2];
					String pM = values[1];
					String pT = values[0];
					intjahr = Integer.parseInt(pJ) - (y + 1900);
					intmonat = Integer.parseInt(pM) - 1;
					inttag = Integer.parseInt(pT) - 1;

					if (pM.length() == 1) {
						pM = "0" + pM;
					}
					if (pT.length() == 1) {
						pT = "0" + pT;
					}
				}

				// Jahr //
				String[] jahreArray = new String[31];

				jahreArray[0] = "";
				for (int i = 1; i < 30 + 1; i++) {
					jahreArray[i] = Integer.toString(i + y + 1899);

				}

				jahr.removeAllItems();

				for (String s : jahreArray) {
					jahr.addItem(s);
				}

				jahr.setSelectedIndex(intjahr + 1);

				jahr.setBounds(330, 56, 85, 20);
				centerpanel.add(jahr);

				// Monat //
				String[] monatsArray = new String[13];

				monatsArray[0] = "";
				for (int i = 1; i < 13; i++) {
					String s = "";
					if (i < 10) {
						s = "0";
					}
					s += Integer.toString(i);
					monatsArray[i] = s;
				}

				monat.removeAllItems();

				for (String s : monatsArray) {
					monat.addItem(s);
				}

				// removeItem(Object)
				// removeItemAt(int)
				// removeAllItems()
				// und
				// addItem(Object)
				monat.setSelectedIndex(intmonat + 1);

				monat.setBounds(255, 56, 70, 20);
				centerpanel.add(monat);

				// Tag //
				String[] tagesArray = new String[32];

				tagesArray[0] = "";
				for (int i = 1; i < 32; i++) {
					String s = "";
					if (i < 10) {
						s = "0";
					}
					s += Integer.toString(i);
					tagesArray[i] = s;
				}

				tag.removeAllItems();

				for (String s : tagesArray) {
					tag.addItem(s);
				}

				tag.setSelectedIndex(inttag + 1);

				tag.setBounds(180, 56, 70, 20);
				centerpanel.add(tag);

				// // VERSUCH
				// tempenddate = textField_1.getText();
				textField_2.setVisible(false);

				// Setzt und Erstellt Priority auswahl checkbox
				priority.removeAllItems();

				String[] priorityvalues = { prioTief[speak], prioMittel[speak],
						prioHoch[speak] };
				for (String s : priorityvalues) {
					priority.addItem(s);
				}
				int select = 1;
				if (textField_2.getText().equals(prioTief[speak])) {
					select = 0;
				} else if (textField_2.getText().equals(prioHoch[speak])) {
					select = 2;
				}
				priority.setSelectedIndex(select);
				priority.setBounds(180, 80, 344, 28);
				centerpanel.add(priority);

				textField.setEditable(true);
				cB.setEnabled(true);

				// textField_3.setEditable(true);
				textArea.setEditable(true);

			}
		};

		taskBearbeitenButton.addActionListener(editTask);

		buttonPanel.add(taskBearbeitenButton, gbc_btnWtl);

		Icon iconSave = new ImageIcon("src/pictures/save.png");
		saveButton = new JButton(iconSave);
		saveButton.setToolTipText(savebutton[speak]);
		saveButton.setPreferredSize(new Dimension(40, 40));
		saveButton.setMinimumSize(new Dimension(40, 40));
		saveButton.setMaximumSize(new Dimension(40, 40));
		saveButton.setEnabled(false);
		GridBagConstraints gbc_btnAnt = new GridBagConstraints();
		gbc_btnAnt.insets = new Insets(0, 0, 0, 5);
		gbc_btnAnt.gridx = 3;
		gbc_btnAnt.gridy = 0;

		ActionListener saveTask = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {

				tasklist.setEnabled(true);
				previousTaskButton.setEnabled(true);
				nextTaskButton.setEnabled(true);
				taskBearbeitenButton.setEnabled(true);
				saveButton.setEnabled(false);
				activated = true;

				textField.setEditable(false);
				cB.setEnabled(false);
				textField_1.setVisible(true);

				textField_2.setVisible(true);
				textField_3.setEditable(false);
				textArea.setEditable(false);
				kalender.setEnabled(false);

				@SuppressWarnings("rawtypes")
				SwingWorker worker = new SwingWorker() {

					@Override
					public Object doInBackground() {
						try {
							Class.forName("com.mysql.jdbc.Driver");
							connection = DriverManager
									.getConnection("jdbc:mysql://win9142.informatik.uni-wuerzburg.de:3306?user=awesomefireballs&password=jesus");
						} catch (ClassNotFoundException e) {
							e.printStackTrace();
						} catch (SQLException e) {
							e.printStackTrace();
							return false;
						}

						Statement stat = null;

						try {
							stat = connection.createStatement();

							String name = textField.getText();

							String date = "";

							// DATE // IN RICHTIGEN STRING KONVERTIEREN
							if ((jahr.getSelectedIndex() == 0)
									|| (monat.getSelectedIndex() == 0)
									|| (tag.getSelectedIndex() == 0)) {
								textField_1.setText("");

							} else {

								String stag = String.valueOf(tag
										.getSelectedIndex());
								String smon = String.valueOf(monat
										.getSelectedIndex());
								String sjah = String.valueOf(jahr
										.getSelectedIndex() + 1899 + y);

								if (stag.length() == 1) {
									stag = "0" + stag;
								}
								if (smon.length() == 1) {
									smon = "0" + smon;
								}

								textField_1.setText(stag + "." + smon + "."
										+ sjah);

								date = sjah + "-" + smon + "-" + stag;
							}

							// String prioritaet = textField_2.getText();
							String prioritaet = "";

							if (priority.getSelectedIndex() == 0) {
								prioritaet = "0";
								textField_2.setText(prioTief[speak]);
							} else if (priority.getSelectedIndex() == 2) {
								prioritaet = "2";
								textField_2.setText(prioHoch[speak]);
							} else {
								prioritaet = "1";
								textField_2.setText(prioMittel[speak]);
							}

							String description = textArea.getText();

							stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

							int isDone = 0;
							if (cB.isSelected()) {
								isDone = 1;
							}
							System.out.println("SELECTED TODO:");

							int selectedToDo = kalender.getSelectedIndex();

							int idTodo = cals.get(selectedToDo).getIdCalendar();

							System.out.println(selectedToDo);

							// es wird ein vorgefertigtes update statement
							// erstellt und anschlie���en werden in die
							// jeweiligen fragezeichen, die Strings
							// eingef���gt.
							connection.setAutoCommit(false);

							PreparedStatement pstmt = connection
									.prepareStatement("UPDATE `sopra-ws12-awesome_fireballs`.`Task` SET `idToDo`=?,  `name`=?, `enddate`=?, `priority`=?, `description`=?, `done`=? WHERE `idTask`=?;");
							pstmt.setInt(1, idTodo);
							pstmt.setString(2, name);
							pstmt.setString(3, date);
							pstmt.setString(4, prioritaet);
							pstmt.setString(5, description);
							pstmt.setInt(6, isDone);
							pstmt.setInt(7, globalselectedid);

							pstmt.addBatch();

							ResultSet nextparticipantid = stat
									.executeQuery("SELECT idparticipantsToDo FROM `sopra-ws12-awesome_fireballs`.participantsToDo ORDER BY idparticipantsToDo DESC LIMIT 1;");
							int nextpartid = 0;
							while (nextparticipantid.next()) {
								nextpartid = nextparticipantid.getInt(1) + 1;
							}

							PreparedStatement ppstmt = connection
									.prepareStatement("INSERT INTO `sopra-ws12-awesome_fireballs`.participantsToDo VALUES(?, ?, ?)");

							System.out.println(participants.size());
							System.out.println(participants.toString());

							ResultSet rsparti = getParticipantsToDo(globalselectedid);

							while (rsparti.next()) {
								System.out.println("HUHU1");
								for (int i = 0; i < participants.size(); i++) {
									System.out.println("HUHU2");
									if (rsparti.getInt("idAdress") == Integer
											.parseInt((String) participants
													.get(i))) {
										System.out.println("TEST IF");
										participants.remove(i);
										i = 0;
									}
								}

							}

							System.out.println("HUHU3");
							System.out.println(nextpartid);
							System.out.println(globalselectedid);

							for (int i = 0; i < participants.size(); i++) {
								System.out.println("HUHU4");
								ppstmt.setInt(1, nextpartid + i);
								System.out.println("muschi");
								ppstmt.setInt(2, globalselectedid);
								System.out.println("testsssss");
								ppstmt.setInt(3, Integer
										.parseInt((String) participants.get(i)));
								System.out.println("ggggggggg");
								ppstmt.addBatch();

							}
							System.out.println(pstmt.toString());
							System.out.println(ppstmt.toString());

							// das vorgefertigte statement wird ausgef���hrt
							pstmt.executeBatch();
							ppstmt.executeBatch();
							connection.commit();
							connection.setAutoCommit(true);
							participants.clear();

						} catch (SQLException e) {
							e.printStackTrace();
						}

						return stat;

					}

					@Override
					public void done() {

						if (sorted == 1) {
							updateSorted();
						}
						if (sorted == 0) {
							update();
						}
						if (emailLinkedList != null) {
							if (emailLinkedList.size() > 0) {
								Mail temp = new Mail();

								temp.setTo(emailLinkedList);

								temp.setBetreff("Einladung zu Termin: "
										+ textField.getText());

								temp.setText(globalselectedid + "");

								MyModelEmail mme = new MyModelEmail();
								mme.sendMail(temp, true);
							}
						}

						listselectionactivated = true;

					}

				};
				worker.execute();

			}

		};

		saveButton.addActionListener(saveTask);

		buttonPanel.add(saveButton, gbc_btnAnt);

		/**
		 * Sort Button
		 */
		tickSort = new ImageIcon("src/pictures/tickSort.png");
		datumSort = new ImageIcon("src/pictures/datumSort.png");

		sortButton = new JButton();
		sortButton.setToolTipText(tooltipSort[speak]);

		if (sorted == 0) {
			sortButton.setIcon(tickSort);
		} else if (sorted == 1) {
			sortButton.setIcon(datumSort);
		}

		sortButton.setPreferredSize(new Dimension(80, 40));
		sortButton.setMinimumSize(new Dimension(80, 40));
		sortButton.setMaximumSize(new Dimension(80, 40));
		GridBagConstraints gbc_btnAntall = new GridBagConstraints();
		gbc_btnAntall.insets = new Insets(0, 0, 0, 5);
		gbc_btnAntall.gridx = 4;
		gbc_btnAntall.gridy = 0;

		ActionListener switchSort = new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				if (sorted == 0) {

					sorted = 1;
					sortButton.setIcon(datumSort);
					setListselectionactivated(false);
					updateSorted();
					setListselectionactivated(true);

				} else if (sorted == 1) {

					sorted = 0;
					sortButton.setIcon(tickSort);
					setListselectionactivated(false);
					update();
					setListselectionactivated(true);

				}

			}
		};

		sortButton.addActionListener(switchSort);

		buttonPanel.add(sortButton, gbc_btnAntall);

		/**
		 * Previous Task Button
		 */
		Icon iconBack = new ImageIcon("src/pictures/last.png");

		previousTaskButton = new JButton(iconBack);
		previousTaskButton.setToolTipText(tooltipLast[speak]);
		previousTaskButton.setMaximumSize(new Dimension(40, 40));
		previousTaskButton.setMinimumSize(new Dimension(40, 40));
		previousTaskButton.setPreferredSize(new Dimension(40, 40));
		GridBagConstraints gbc_btnLeft = new GridBagConstraints();
		gbc_btnLeft.insets = new Insets(0, 0, 0, 5);
		gbc_btnLeft.gridx = 6;
		gbc_btnLeft.gridy = 0;

		MouseListener getPrev = new MouseAdapter() {

			@Override
			public void mouseClicked(MouseEvent arg0) {
				if (activated) {
					int aktuell = tasklist.getSelectedIndex();

					if (aktuell != 0) {
						tasklist.setSelectedIndex(aktuell - 1);
					}

				}

			}
		};

		previousTaskButton.addMouseListener(getPrev);

		buttonPanel.add(previousTaskButton, gbc_btnLeft);

		/**
		 * Aktueller Task Anzeigefeld
		 */
		aktuellerTask = new JTextField();
		aktuellerTask.setToolTipText(tooltipAktuell[speak]);
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.insets = new Insets(0, 0, 0, 5);
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.gridx = 7;
		gbc_textField.gridy = 0;
		buttonPanel.add(aktuellerTask, gbc_textField);
		aktuellerTask.setToolTipText(tooltipAktuell[speak]);
		aktuellerTask.setDisabledTextColor(new Color(0, 0, 0));
		aktuellerTask.setEnabled(false);
		aktuellerTask.setEditable(false);
		aktuellerTask.setColumns(10);

		/**
		 * Next Task Button
		 */
		Icon iconForward = new ImageIcon("src/pictures/next.png");
		nextTaskButton = new JButton(iconForward);
		nextTaskButton.setToolTipText(tooltipNext[speak]);
		nextTaskButton.setPreferredSize(new Dimension(40, 40));
		nextTaskButton.setMinimumSize(new Dimension(40, 40));
		nextTaskButton.setMaximumSize(new Dimension(40, 40));
		GridBagConstraints gbc_btnRight = new GridBagConstraints();
		gbc_btnRight.gridx = 8;
		gbc_btnRight.gridy = 0;

		MouseListener getNext = new MouseAdapter() {

			@Override
			public void mouseClicked(MouseEvent arg0) {
				if (activated) {
					int aktuell = tasklist.getSelectedIndex();

					if (aktuell != tasklist.getModel().getSize()) {
						tasklist.setSelectedIndex(aktuell + 1);

					}

				}

			}
		};

		nextTaskButton.addMouseListener(getNext);

		buttonPanel.add(nextTaskButton, gbc_btnRight);

		/**
		 * LINKES PANEL MIT TASKLISTE WIRD ERSTELLT
		 */
		JPanel westpanel = new JPanel();
		westpanel.setLayout(new BorderLayout(0, 0));
		add(westpanel, BorderLayout.WEST);

		// Liste in welche Tasks mit name + enddate eingefuegt werden
		tasklist = new JList();
		// final JList datelist = new JList();
		tasklist.setVisibleRowCount(20);
		// datelist.setVisibleRowCount(26);
		dlm = new DefaultListModel();

		// DefaultListModel dlmdate = new DefaultListModel();
		if (sorted == 1) {
			updateSorted();
		}
		if (sorted == 0) {
			update();
		}

		ListSelectionListener lsl = new ListSelectionListener() {

			@Override
			public void valueChanged(ListSelectionEvent e) {

				if (getListselectionactivated()) {
					int index = tasklist.getSelectedIndex();

					aktuellerTask.setText(taskslinkedlist.get(index)
							.toStringShort());
					aktuellerTask.setCaretPosition(0);

					int userid = taskslinkedlist.get(index).getId();
					globalselectedid = userid;

					try {
						temp.absolute(1);

						ResultSet participants = null;
						participants = getParticipants(userid);

						if (temp.getInt("idTask") == userid) {

							textField.setText(temp.getString("name"));

							if (temp.getInt("done") == 0) {
								cB.setSelected(false);
							} else {
								cB.setSelected(true);
							}

							// // Dreht den String von Date um. ////
							String sd = temp.getString("enddate");
							String ds = "";

							if ((sd != "")) {
								String[] values = sd.split("-");
								if (values.length == 3) {
									// Setzt Nullen vor die einstelligen
									// Monatszahlen
									String nullString3 = "";
									String nullString4 = "";
									if (values[2].length() == 1) {
										nullString3 = "0";
									}
									if (values[1].length() == 1) {
										nullString4 = "0";
									}
									ds = nullString3 + values[2] + "."
											+ nullString4 + values[1] + "."
											+ values[0];
								}

							}

							textField_1.setText(ds);

							if (temp.getInt("priority") == 0) {
								textField_2.setText(prioTief[speak]);
							} else if (temp.getInt("priority") == 2) {
								textField_2.setText(prioHoch[speak]);
							} else {
								textField_2.setText(prioMittel[speak]);
							}

							String participantString = "";

							while (participants.next()) {

								if (participants.isLast()) {

									participantString = participantString
											+ participants.getString("fname")
											+ " "
											+ participants.getString("lname");

								} else {

									participantString = participantString
											+ participants.getString("fname")
											+ " "
											+ participants.getString("lname")
											+ ", ";

								}

							}
							textField_3.setText(participantString);

							Statement stat;
							stat = connection.createStatement();
							stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

							ResultSet idsCalendar = stat
									.executeQuery("SELECT idCalendar, name, idCreator FROM Calendar WHERE idUser = "
											+ Test.iduser + ";");

							while (idsCalendar.next()) {
								CheckboxCalendar temp = new CheckboxCalendar(
										idsCalendar.getInt("idCalendar"),
										idsCalendar.getString("name"),
										idsCalendar.getInt("idCreator"));
								cals.add(temp);
							}

							@SuppressWarnings("unused")
							int position = temp.getInt("idToDo");
							String posName = "";

							for (int i = 0; i < cals.size(); i++) {

								if (cals.get(i).getIdCalendar() == temp
										.getInt("idToDo")) {
									posName = cals.get(i).getName();
								}
							}

							for (int i = 0; i < calDropdown.length; i++) {
								if (calDropdown[i].equals(posName)) {

								}
							}

							System.out.println(kalender.getSelectedIndex());

							kalender.setEnabled(true);
							kalender.setSelectedItem(posName);

							kalender.setEnabled(false);

							textArea.setText(temp.getString("description"));

						}

						while (temp.next()) {

							if (temp.getInt("idTask") == userid) {

								if (temp.getInt("done") == 0) {
									cB.setSelected(false);
								} else {
									cB.setSelected(true);
								}

								textField.setText(temp.getString("name"));

								// // Dreht den String von Date um. ////
								String sd = temp.getString("enddate");
								String ds = "";
								if ((sd != "")) {
									String[] values = sd.split("-");
									if (values.length == 3) {
										// Setzt Nullen vor die einstelligen
										// Monatszahlen
										String nullString3 = "";
										String nullString4 = "";
										if (values[2].length() == 1) {
											nullString3 = "0";
										}
										if (values[1].length() == 1) {
											nullString4 = "0";
										}
										ds = nullString3 + values[2] + "."
												+ nullString4 + values[1] + "."
												+ values[0];
									}
								}

								textField_1.setText(ds);

								if (temp.getInt("priority") == 0) {
									textField_2.setText(prioTief[speak]);
								} else if (temp.getInt("priority") == 2) {
									textField_2.setText(prioHoch[speak]);
								} else {
									textField_2.setText(prioMittel[speak]);
								}

								String participantString = "";

								while (participants.next()) {

									if (participants.isLast()) {

										participantString = participantString
												+ participants
														.getString("fname")
												+ " "
												+ participants
														.getString("lname");

									} else {

										participantString = participantString
												+ participants
														.getString("fname")
												+ " "
												+ participants
														.getString("lname")
												+ ", ";

									}

								}
								textField_3.setText(participantString);

								Statement stat;
								stat = connection.createStatement();
								stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

								ResultSet idsCalendar = stat
										.executeQuery("SELECT idCalendar, name, idCreator FROM Calendar WHERE idUser = "
												+ Test.iduser + ";");

								while (idsCalendar.next()) {
									CheckboxCalendar temp = new CheckboxCalendar(
											idsCalendar.getInt("idCalendar"),
											idsCalendar.getString("name"),
											idsCalendar.getInt("idCreator"));
									cals.add(temp);
								}

								@SuppressWarnings("unused")
								int position = temp.getInt("idToDo");
								String posName = "";

								for (int i = 0; i < cals.size(); i++) {

									if (cals.get(i).getIdCalendar() == temp
											.getInt("idToDo")) {
										posName = cals.get(i).getName();
									}
								}

								for (int i = 0; i < calDropdown.length; i++) {
									if (calDropdown[i].equals(posName)) {

									}
								}

								System.out.println(kalender.getSelectedIndex());

								kalender.setEnabled(true);
								kalender.setSelectedItem(posName);

								kalender.setEnabled(false);

								textArea.setText(temp.getString("description"));

							}

						}

					} catch (SQLException e1) {
						e1.printStackTrace();
					}
				}

			}
		};

		tasklist.setModel(dlm);
		tasklist.addListSelectionListener(lsl);

		// datelist.setModel(dlmdate);

		// Einfuegen der Liste in ScrollPane und danach in Linkes Panel
		JScrollPane scrollPanetask = new JScrollPane(tasklist);
		scrollPanetask.setPreferredSize(new Dimension(280, 590));
		// JScrollPane scrollPanedate = new JScrollPane(datelist);
		westpanel.add(scrollPanetask);
		// westpanel.add(scrollPanedate, BorderLayout.CENTER);

		/**
		 * RECHTS PANEL MIT DETAILANSICHT WIRD ERSTELLT
		 */
		centerpanel = new JPanel();
		centerpanel.setBackground(new Color(r, g, b));
		add(centerpanel, BorderLayout.CENTER);
		centerpanel.setLayout(null);

		// Erstellen der Label zu jeweiligen Textfeldern
		JLabel lblName = new JLabel(titel[speak]);
		lblName.setHorizontalAlignment(SwingConstants.RIGHT);
		lblName.setBounds(50, 30, 97, 16);
		centerpanel.add(lblName);

		JLabel lblStrae = new JLabel(abgabe[speak]);
		lblStrae.setHorizontalAlignment(SwingConstants.RIGHT);
		lblStrae.setBounds(50, 58, 97, 16);
		centerpanel.add(lblStrae);

		JLabel lblPlz = new JLabel(prior[speak]);
		lblPlz.setHorizontalAlignment(SwingConstants.RIGHT);
		lblPlz.setBounds(50, 86, 97, 16);
		centerpanel.add(lblPlz);

		JLabel lblStadt = new JLabel(teilnehmer[speak]);
		lblStadt.setHorizontalAlignment(SwingConstants.RIGHT);
		lblStadt.setBounds(50, 114, 97, 16);
		centerpanel.add(lblStadt);

		JLabel lblErledigt = new JLabel("Erledigt");
		lblErledigt.setHorizontalAlignment(SwingConstants.RIGHT);
		lblErledigt.setBounds(50, 142, 97, 16);
		centerpanel.add(lblErledigt);

		JLabel lblKalendar = new JLabel(kalendar[speak]);
		lblKalendar.setHorizontalAlignment(SwingConstants.RIGHT);
		lblKalendar.setBounds(50, 173, 97, 16);
		centerpanel.add(lblKalendar);

		JLabel lblEmail = new JLabel(beschreibung[speak]);
		lblEmail.setHorizontalAlignment(SwingConstants.RIGHT);
		lblEmail.setBounds(50, 204, 97, 16);
		centerpanel.add(lblEmail);

		// Erstellen der Textfelder

		// Titel
		textField = new JTextField();
		textField.setBounds(180, 24, 344, 28);
		centerpanel.add(textField);
		textField.setColumns(10);
		textField.setEditable(false);

		// Date
		textField_1 = new JTextField();
		textField_1.setBounds(180, 52, 344, 28);
		centerpanel.add(textField_1);
		textField_1.setColumns(10);
		textField_1.setEditable(false);

		// Prioritaet
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(180, 80, 344, 28);
		centerpanel.add(textField_2);
		textField_2.setEditable(false);

		// Teilnehmer
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(180, 108, 309, 28);
		centerpanel.add(textField_3);
		textField_3.setEditable(false);

		// Kalender
		Statement stat;
		ResultSet idsCalendar;
		try {
			stat = connection.createStatement();
			stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

			idsCalendar = stat
					.executeQuery("SELECT idCalendar, name, idCreator FROM Calendar WHERE idUser = "
							+ Test.iduser + ";");
			while (idsCalendar.next()) {
				CheckboxCalendar temp = new CheckboxCalendar(
						idsCalendar.getInt("idCalendar"),
						idsCalendar.getString("name"),
						idsCalendar.getInt("idCreator"));
				cals.add(temp);
			}
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		calDropdown = new String[cals.size()];
		for (int i = 0; i < cals.size(); i++) {
			calDropdown[i] = cals.get(i).getName();
		}

		kalender = new JComboBox(calDropdown);

		kalender.setBounds(180, 173, 344, 28);
		centerpanel.add(kalender);
		kalender.setEnabled(false);

		// Details
		textArea = new JTextArea();
		JScrollPane textAreaScroll = new JScrollPane(textArea);
		textAreaScroll.setBounds(180, 204, 344, 250);

		centerpanel.add(textAreaScroll);
		textArea.setEditable(false);

		/**
		 * Button um Teilnehmer zu einem Task hinzuzufuegen, hierfuer wird ein
		 * weiteres Fenster geoeffnet welches eine Liste von Kontakten enthaelt
		 */
		JButton btnAddParticipants = new JButton("+");
		btnAddParticipants.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {

				AddContactWindow addcontact = new AddContactWindow(tdp, false);
				addcontact.setVisible(true);
			}
		});
		btnAddParticipants.setBounds(495, 109, 29, 27);
		centerpanel.add(btnAddParticipants);

		cB = new JCheckBox("");
		cB.setEnabled(false);
		cB.setBounds(180, 143, 21, 23);
		centerpanel.add(cB);

	}

	// Additional Methods
	/**
	 * Erzeugt Update auf aufgabenlisten nach sortierung
	 */
	@SuppressWarnings("deprecation")
	public void updateSorted() {

		tasklist.setEnabled(false);

		// Verbindung zur Datenbank herstellen
		connect();
		dlm.clear();
		taskslinkedlist.clear();

		ResultSet tasks = null;

		try {
			// Holt ResultSet mit allen Tasks aus DB
			tasks = getTasksFromDb();
			LinkedList<Integer> calids = getCalIds();

			// / SORTIERT SET

			ArrayList<String> sl = new ArrayList<String>();
			ArrayList<MyTask> tl = new ArrayList<MyTask>();

			while (tasks.next()) {
				if (tasks.getInt("done") == 0) {

					// dreht das Datum um
					String datString = tasks.getString("enddate");

					Date enddate2 = new Date();
					DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
					try {
						enddate2 = df.parse(datString);
					} catch (ParseException e) {
						e.printStackTrace();
					}

					// setzt Nullen
					String tag = enddate2.getDate() + "";
					String monat = (enddate2.getMonth() + 1) + "";
					if (enddate2.getDate() < 10) {
						tag = "0" + tag;
					}
					if (enddate2.getMonth() < 9) {
						monat = "0" + monat;
					}

					String datumString = tag + "." + monat + "."
							+ (enddate2.getYear() + 1900);
					//

					if (zuerstDatum == 0) {
						sl.add("    " + datumString + ", "
								+ tasks.getString("name"));
					} else {
						sl.add("    " + tasks.getString("name") + ", "
								+ datumString);
					}

					String date = tasks.getString("enddate");

					Date enddate = new Date();

					try {
						enddate = df.parse(date);
					} catch (ParseException e) {
						e.printStackTrace();
					}

					MyTask task = new MyTask(tasks.getString("name"), enddate,
							tasks.getInt("idTask"));
					task.setTodoid(tasks.getInt("idToDo"));
					if (tasks.getInt("done") == 0) {
						task.setDone(false);
					} else {
						task.setDone(true);
					}
					tl.add(task);

				}
			}

			tasks.absolute(1);

			while (tasks.next()) {
				if (tasks.getInt("done") == 1) {

					// dreht das Datum um
					String datString = tasks.getString("enddate");

					Date enddate2 = new Date();
					DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
					try {
						enddate2 = df.parse(datString);
					} catch (ParseException e) {
						e.printStackTrace();
					}
					// setzt Nullen
					String tag = enddate2.getDate() + "";
					String monat = (enddate2.getMonth() + 1) + "";
					if (enddate2.getDate() < 10) {
						tag = "0" + tag;
					}
					if (enddate2.getMonth() < 9) {
						monat = "0" + monat;
					}

					String datumString = tag + "." + monat + "."
							+ (enddate2.getYear() + 1900);
					//

					if (zuerstDatum == 0) {
						sl.add("✓ " + datumString + ", "
								+ tasks.getString("name"));
					} else {
						sl.add("✓ " + tasks.getString("name") + ", "
								+ datumString);
					}

					String date = tasks.getString("enddate");

					Date enddate = new Date();

					try {
						enddate = df.parse(date);
					} catch (ParseException e) {
						e.printStackTrace();
					}

					MyTask task = new MyTask(tasks.getString("name"), enddate,
							tasks.getInt("idTask"));
					task.setTodoid(tasks.getInt("idToDo"));

					if (tasks.getInt("done") == 0) {
						task.setDone(false);
					} else {
						task.setDone(true);
					}
					tl.add(task);
				}
			}

			for (int i = 0; i < sl.size(); i++) {

				for (int j = 0; j < calids.size(); j++) {

					if (calids.get(j) == tl.get(i).getTodoid()) {

						taskslinkedlist.add(tl.get(i));

						// String elementdate = tasks.getString("enddate");
						// Fuegt jeweiliges Element in Liste ein

						dlm.addElement(sl.get(i));
					}
				}

			}

		} catch (SQLException e) {

			e.printStackTrace();
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		}
		temp = tasks;
		tasklist.setEnabled(true);

	}

	/**
	 * Updatet Listen
	 */
	@SuppressWarnings("deprecation")
	public void update() {

		tasklist.setEnabled(false);

		// Verbindung zur Datenbank herstellen
		connect();
		dlm.clear();
		taskslinkedlist.clear();

		ResultSet tasks = null;
		try {
			// Holt ResultSet mit allen Tasks aus DB
			tasks = getTasksFromDb();
			LinkedList<Integer> calids = getCalIds();

			while (tasks.next()) {

				// Erstellt String mit abgabedatum und name
				String elementtask;

				// dreht das Datum um
				String datString = tasks.getString("enddate");

				Date enddate2 = new Date();
				DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
				try {
					enddate2 = df.parse(datString);
				} catch (ParseException e) {
					e.printStackTrace();
				}
				// setzt Nullen
				String tag = enddate2.getDate() + "";
				String monat = (enddate2.getMonth() + 1) + "";
				if (enddate2.getDate() < 10) {
					tag = "0" + tag;
				}
				if (enddate2.getMonth() < 9) {
					monat = "0" + monat;
				}

				String datumString = tag + "." + monat + "."
						+ (enddate2.getYear() + 1900);//

				if (tasks.getInt("done") == 1) {

					if (zuerstDatum == 0) {
						elementtask = "✓ " + datumString + ", "
								+ tasks.getString("name");
					} else {
						elementtask = "✓ " + tasks.getString("name") + ", "
								+ datumString;
					}

				} else {

					if (zuerstDatum == 0) {
						elementtask = "    " + datumString + ", "
								+ tasks.getString("name");
					} else {
						elementtask = "    " + tasks.getString("name") + ", "
								+ datumString;
					}

				}

				String date = tasks.getString("enddate");

				Date enddate = new Date();
				try {
					enddate = df.parse(date);
				} catch (ParseException e) {
					e.printStackTrace();
				}

				MyTask task = new MyTask(tasks.getString("name"), enddate,
						tasks.getInt("idTask"));

				if (tasks.getInt("done") == 0) {
					task.setDone(false);
				} else {
					task.setDone(true);
				}

				for (int i = 0; i < calids.size(); i++) {

					if (calids.get(i) == tasks.getInt("idToDo")) {
						taskslinkedlist.add(task);

						// String elementdate = tasks.getString("enddate");
						// Fuegt jeweiliges Element in Liste ein
						dlm.addElement(elementtask);
					}
				}

			}

		} catch (SQLException e) {

			e.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		temp = tasks;
		tasklist.setEnabled(true);

	}

	/**
	 * Methode skaliert Bilder effizienter
	 * 
	 * @param ret
	 *            Bild das Skaliert werden soll
	 * @param w
	 *            Breite die das Bild danach haben soll
	 * @param h
	 *            H�he die das Bild danach haben wird
	 * @return skaliertes Bild mit den Werten w und h
	 */
	public Image resize(Image ret, int w, int h) {

		BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
		Graphics2D g2 = tmp.createGraphics();
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
				RenderingHints.VALUE_INTERPOLATION_BILINEAR);
		g2.drawImage(ret, 0, 0, w, h, null);
		g2.dispose();
		return tmp;
	}

	public void setParticipantsText() {

		emailLinkedList = new LinkedList<String>();
		String mail = "";
		String s = "";
		Statement stat;
		try {
			stat = connection.createStatement();

			stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

			for (int i = 0; i < participants.size(); i++) {
				ResultSet rs = stat
						.executeQuery("SELECT Adress.* FROM Adress WHERE idAdress= "
								+ participants.get(i) + ";");
				rs.next();
				s += rs.getString("fname") + " ";
				s += rs.getString("lname") + ", ";
				mail = rs.getString("email");
				emailLinkedList.add(mail);

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		textField_3.setText(s);
	}

	public boolean getListselectionactivated() {
		return listselectionactivated;
	}

	public void setListselectionactivated(boolean listselectionactivated) {
		this.listselectionactivated = listselectionactivated;
	}

	/**
	 * Gibt ein RS mit allen Teilnehmern von einem Task zurueck
	 * 
	 * @param id
	 * @return
	 * @throws SQLException
	 */
	public ResultSet getParticipantsToDo(int id) throws SQLException {

		Integer help = new Integer(id);
		String idString = "'" + help.toString() + "'";

		Statement stat = connection.createStatement();
		stat.executeQuery("use `sopra-ws12-awesome_fireballs`;");

		ResultSet rs = stat
				.executeQuery("SELECT Adress.* FROM Task, participantsToDo, Adress where Task.idTask = "
						+ idString
						+ "AND Adress.idAdress = participantsToDo.idAdress AND participantsToDo.idTask = Task.idTask group by Adress.idAdress;");

		return rs;

	}
}
